package com.ostrich.cloud.ostrichUserWeb.app.ApiImp;

import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.common.result.PageResult;
import com.ostrich.cloud.common.result.Result;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.GoodsDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.GetGoodsParam;
import com.ostrich.cloud.ostrichGoodsService.client.GoodsClient;
import com.ostrich.cloud.ostrichUserWeb.client.CustomerGoodsManagerClient;
import com.ostrich.cloud.ostrichUserWeb.client.goodsParam.GetGoodsBuTypeId;
import com.ostrich.cloud.ostrichUserWeb.client.goodsParam.GetGoodsByBusinessman;
import com.ostrich.cloud.ostrichUserWeb.client.goodsParam.GetGoodsLikeGoodsName;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class CustomerGoodsManagerApiImp implements CustomerGoodsManagerClient {
    @Resource
    private GoodsClient goodsClient;


    @Override
    public Result getAllGoods(GetGoodsByBusinessman getGoodsByBusinessman) {
        GetGoodsParam param= BeanUtil.copyProperties(getGoodsByBusinessman,GetGoodsParam.class);
        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);

        return goodsByCriteria;
    }

    @Override
    public Result getGoodsByType(GetGoodsBuTypeId getGoodsBuTypeId) {
        GetGoodsParam param=BeanUtil.copyProperties(getGoodsBuTypeId,GetGoodsParam.class);

        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);

        return goodsByCriteria;
    }

    @Override
    public Result getGoodsLikeName(GetGoodsLikeGoodsName getGoodsLikeGoodsName) {
        GetGoodsParam param=BeanUtil.copyProperties(getGoodsLikeGoodsName,GetGoodsParam.class);

        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);

        return goodsByCriteria;
    }

    @Override
    public Result getGoods(Integer goodsId) {
        GoodsDto goodsDto = goodsClient.getGoodsDto(goodsId);
        return Result.ok(goodsDto);
    }
}
